package com.base.invoke.utils;

import org.apache.commons.codec.digest.DigestUtils;


/**
 * MD5加密工具类
 * @author coolpig
 * @date 2019-09-27
 */
public class MD5Util {

    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    private static final String salt = "1a2b3c4d5e7g8h9i0j";

    public static String inPwdtoFormPwd(String inputPass) {
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        System.out.println(str);
        return md5(str);
    }

    public static String formPwdToDBPwd(String formPass, String salt) {
        String str = "" + salt.charAt(0)+ salt.charAt(2) + formPass + salt.charAt(5) + salt.charAt(4);
        return md5(str);
    }

    public static String inPwdToDbPwd(String inputPass, String saltDB) {
        String formPass = inPwdtoFormPwd(inputPass);
        String dbPass = formPwdToDBPwd(formPass, saltDB);
        return dbPass;
    }

    public static void main(String[] args) {
        System.out.println(inPwdtoFormPwd("123456"));
		System.out.println(formPwdToDBPwd(inPwdtoFormPwd("123456"), "123qwe"));
		System.out.println(inPwdToDbPwd("123456", "123qwe"));
    }
}
